<template>
  <div>
    <el-button v-if="!select" type="primary" @click="visible = true" icon="el-icon-circle-plus-outline">新增</el-button>
    <el-table v-loading="loading" :data="dataSource" @row-click="handleRowClick">
      <el-table-column prop="roleName" label="名称" align="center">
        <template slot="header" slot-scope="scope">
          <div>{{ scope.column.label }}</div>
          <el-input v-model="filterModel[scope.column.property]" :placeholder="scope.column.label + '过滤'" clearable @change="filterChange(scope.column.property)"></el-input>
        </template>
      </el-table-column>
      <el-table-column prop="roleCode" label="编码" align="center">
        <template slot="header" slot-scope="scope">
          <div>{{ scope.column.label }}</div>
          <el-input v-model="filterModel[scope.column.property]" :placeholder="scope.column.label + '过滤'" clearable @change="filterChange(scope.column.property)"></el-input>
        </template>
      </el-table-column>
      <el-table-column prop="roleLevel" label="级别" align="center">
        <template slot="header" slot-scope="scope">
          <div>{{ scope.column.label }}</div>
          <el-input v-model="filterModel[scope.column.property]" :placeholder="scope.column.label + '过滤'" clearable @change="filterChange(scope.column.property)"></el-input>
        </template>
      </el-table-column>
      <el-table-column prop="roleAbility" label="能力" align="center">
        <template slot="header" slot-scope="scope">
          <div>{{ scope.column.label }}</div>
          <el-input v-model="filterModel[scope.column.property]" :placeholder="scope.column.label + '过滤'" clearable @change="filterChange(scope.column.property)"></el-input>
        </template>
      </el-table-column>
      <el-table-column prop="dataState" label="状态" align="center" width="80px">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.dataState >=0 ">正常</el-tag>
          <el-tag v-else type="danger">禁用</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="100px">
        <div slot-scope="scope">
          <template v-if="select">
            <el-button type="success" icon="el-icon-thumb" circle @click="$emit('rowSelect',scope.row)" title="选择"></el-button>
          </template>
          <template v-else>
            <el-button type="success" icon="el-icon-edit" circle @click="() => { entityInfo=$Util.copy(scope.row);visible=true}" title="编辑"></el-button>
            <el-button type="danger" icon="el-icon-delete" circle @click="removeData(scope.row, scope.$index)" title="删除"></el-button>
          </template>
        </div>
      </el-table-column>
    </el-table>
    <div class="lab-table-page">
      <div style="display: inline-flex">
        <el-pagination
            :disabled="loading"
            :current-page="pageInfo.page"
            :page-sizes="[5, 10, 15, 20, 50, 100]"
            :page-size="pageInfo.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="pageInfo.total"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
        />
        <el-button-group style="padding: 2px 5px">
          <el-button icon="el-icon-refresh" title="刷新" :disabled="loading" @click="loadSource([])" />
        </el-button-group>
      </div>
    </div>

    <el-dialog :visible.sync="visible" title="菜单信息">
      <el-form label-position="right" label-width="80px">
        <el-form-item label="名称" required>
          <el-input v-model="entityInfo.roleName" placeholder="角色名称"/>
        </el-form-item>
        <el-form-item label="编码">
          <el-input v-model="entityInfo.roleCode" placeholder="角色编码"/>
        </el-form-item>
        <el-form-item label="级别">
          <el-input-number v-model="entityInfo.roleLevel" controls-position="right" placeholder="角色级别" style="width: 100%"/>
        </el-form-item>
        <el-form-item label="能力">
          <el-input type="textarea" :rows="4"  v-model="entityInfo.roleAbility" placeholder="角色能力"/>
        </el-form-item>
        <el-form-item label="状态">
          <el-radio-group v-model="entityInfo.dataState">
            <el-radio :label="-1">禁用</el-radio>
            <el-radio :label="0">正常</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-circle-check" type="success" @click="saveData(entityInfo)">{{ entityInfo.roleId ? '更新' : '保存' }}</el-button>
          <el-button icon="el-icon-circle-close" type="info" @click="visible = false">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import IdeaTable from "@/mixins/IdeaTable";

export default {
  name: "RoleTable",
  mixins: [IdeaTable],
  props: {
    select: {
      type: Boolean,
      default: false
    }
  },
  created() {
    this.queryUrl = '/groupRole/queryPage'
    this.saveUrl = '/groupRole/save'
    this.removeUrl = '/groupRole/delete/'
    this.rowKey = 'roleId'
    this.loadSource()
  }
}
</script>

<style scoped>

</style>
